/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.mycompany.chatapp;

import java.io.Serializable;
import java.awt.Image;
import java.awt.image.renderable.ParameterBlock;
import javax.media.jai.*;
import javax.swing.ImageIcon;
import org.apache.log4j.Logger;

/**
 *
 * @author Group C
 */
public class ImpThumbnail implements Thumbnail, Serializable
{   
   //private ImageIcon image;
   public RenderedOp temp, output=null;
   //Logger for ImpInstantMessage
   private final static Logger log = Logger.getLogger(ImpThumbnail.class);

    public ImpThumbnail(String imageLocation, String heighH, String widthW)
    {
        log.info("Thumbnail 1 ");
        log.info("Path del thumbnail "+imageLocation);
        RenderedOp myImage = JAI.create("fileload",imageLocation);
        //float height= Float.parseFloat(heighH);
        //float width = Float.parseFloat(widthW);
        float height = myImage.getHeight();
        float width = myImage.getWidth();
        log.info("Thumbnail 2 "+height);
        log.info("Thumbnail 2 "+(width));
        //the heigth and width of the square is 100. In order to obtain 100 in the end, we have to calculate
        //the xScale and yScale necessary for it
        float thumbHeight=100/height;
        float thumbWidth=100/width;
         log.info("Thumbnail 3 "+(thumbHeight));
        //int thumbHeightInt= (int)thumbHeight;
        //int thumbWidthInt= (int) thumbWidth;
        ParameterBlock pb = new ParameterBlock();
        pb.addSource(myImage);
        pb.add(thumbWidth);
        pb.add(thumbHeight);
        pb.add(0.0F);
        pb.add(0.0F);
        pb.add(new InterpolationNearest());
        temp=JAI.create("scale",pb,null);
        JAI.create("filestore", temp, "/Users/maggiesd/out.jpg" , "JPEG");
        //ImageIcon picture=new ImageIcon(imageLocation);
        log.info("Thumbnail 4 "+thumbWidth);
        //image=new ImageIcon(picture.getImage().getScaledInstance(thumbHeightInt,thumbWidthInt,Image.SCALE_DEFAULT));
        log.info("Thumbnail 5");
    } 
    
    public RenderedOp getImage()
    {
        return output;
    }
}
